package offer_test_20;

//给定单向链表的头指针和一个结点指针，定义一个函数在O(1)时间删除该结点。
import struct.LinkedNode;

public class thriteen_DelteNodeInO1 {
	public static void main(String[] args) {

		LinkedNode head = new LinkedNode();
		LinkedNode second = new LinkedNode();
		LinkedNode third = new LinkedNode();
		head.next = second;
		second.next = third;
		head.data = 1;
		second.data = 2;
		third.data = 3;
		deleteNode(second, head);
		System.out.println(head.next.data);

	}

	public static void deleteNode(LinkedNode node, LinkedNode firstnode) {
		if (node.next != null) {
			node.data=node.next.data;
			node.next = node.next.next;
		} else {
			LinkedNode pointListNode=firstnode;
			while (!pointListNode.next.equals(node)) {
				pointListNode = pointListNode.next;
			}
			pointListNode.next = null;
		}
	}
}
